﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.JShop.UI;
using CNVP.Config;
using CNVP.Framework;
using System.Text.RegularExpressions;

namespace CNVP.JShop.Web.Admin
{
    public partial class SchemeRulesSet : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!BLL.BLLCheckAdmin.LoginOk(Page, 137)) return;//判断页面权限
            if (!IsPostBack)
            {
                txtAdd.Text = SchemeRules.GetConfigValue("Add");
                txtEdit.Text = SchemeRules.GetConfigValue("Edit");
                txtDay.Text = SchemeRules.GetConfigValue("Day");
                txtNight.Text = SchemeRules.GetConfigValue("Night");
            }
        }

        protected void btUp_Click(object sender, EventArgs e)
        {
            string _Add = txtAdd.Text.Trim();
            string _Edit = txtEdit.Text.Trim();
            string _Day = txtDay.Text.Trim();
            string _Night = txtNight.Text.Trim();
            
            Regex re = new Regex(@"^\d+$");
           
           
            if (re.IsMatch(_Add) && re.IsMatch(_Edit) && re.IsMatch(_Day) && re.IsMatch(_Night))
            {
                if (int.Parse(_Add) % 2 == 0 && int.Parse(_Edit) % 2 == 0 && int.Parse(_Day) % 2 == 0 && int.Parse(_Night) % 2 == 0)
                {
                    SchemeRules.SaveXmlConfig("Add", _Add);
                    SchemeRules.SaveXmlConfig("Edit", _Edit);
                    SchemeRules.SaveXmlConfig("Day", _Day);
                    SchemeRules.SaveXmlConfig("Night", _Night);
                    SchemeRules.RefurbishCatch();//刷新缓存
                    BasePage.MessageBox("修改成功！", "SchemeRulesSet.aspx");
                }
                else
                {
                    BasePage.MessageBox("积分必须是2的整数倍！", "SchemeRulesSet.aspx");
                }
            }
            else
            {
                BasePage.MessageBox("请检查你输入的都是正整数.", "SchemeRulesSet.aspx");
              
            }
        }
    }
}